﻿#region zh-CHS 2006 - 2010 DemoSoft 团队 | en 2006-2010 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2010 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Collections;
using System.Collections.Generic;
using Demo.Mmose.Core.Common;
using Demo.Mmose.Core.Common.SafeCollections;
#endregion

namespace Demo.Mmose.Core.Entity.Suit.Spell
{
    /// <summary>
    /// 
    /// </summary>
    public class SpellLineManager : IEnumerable<SpellLine>
    {
        #region zh-CHS 共有属性 | en Public Properties
        /// <summary>
        /// 
        /// </summary>
        public int Count
        {
            get { return m_SpellLines.Count; }
        }
        #endregion

        #region zh-CHS 共有方法 | en Public Methods

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private SafeDictionary<long, SpellLine> m_SpellLines = new SafeDictionary<long, SpellLine>();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="baseTaxiNode"></param>
        public void AddSpellLine( long spellLineId, SpellLine spellLine )
        {
            if ( spellLine == null )
                throw new ArgumentNullException( "spellLine", "SpellLineManager.AddSpellTemplate(...) - spellLine == null error!" );

            m_SpellLines.Add( spellLineId, spellLine );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void RemoveSpellLine( long spellLineId )
        {
            m_SpellLines.Remove( spellLineId );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="auraId"></param>
        /// <returns></returns>
        public SpellLine FindSpellLineOnId( long spellLineId )
        {
            SpellLine spellLine = null;

            if ( m_SpellLines.TryGetValue( spellLineId, out spellLine ) == false )
                return null;
            else
                return spellLine;
        }

        /// <summary>
        /// 
        /// </summary>
        [MultiThreadedWarning( "zh-CHS", "(SpellTemplate)当前的数组是列表临时产生的,不能保存数组用于以后操作:警告!" )]
        public SpellLine[] ToArray()
        {
            return m_SpellLines.ToArrayValues();
        }

        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator<SpellLine> GetEnumerator()
        {
            SpellLine[] tempSpellLineArray = this.ToArray();
            if ( tempSpellLineArray == null )
                yield break;

            for ( int iIndex = 0; iIndex < tempSpellLineArray.Length; iIndex++ )
                yield return tempSpellLineArray[iIndex];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
        #endregion
    }
}
#endregion